﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ProjetPacman;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace pacman
{
    class Animation
    {
        private List<Frame> frames;
        private int _step;
        private long retard;

        public void AddFrame(Frame f)
        {
            frames.Add(f);
        }

        public Animation()
        {
            frames = new List<Frame>();
            _step = 0;
            retard = 0;
        }

        public void Start()
        {
            _step = 0;
        }

        public void Refresh(long temps)
        {
            long duree = temps + retard;

            while (duree >= frames[_step].Delay)
            {
                duree -= frames[_step].Delay;
                _step++;
                if (_step >= frames.Count)
                {
                    Start();
                }
                retard = duree;
            }
        }

        public void Draw(SpriteBatch spriteBatch, Vector2 position)
        {
            frames[_step].Draw(spriteBatch, position);
        }
    }
}
